我在AWS EC2同一个实例下挂了2个WordPress,第一个一切正常,第二个除了主页,访问其他页面都提示“The requested URL was not found on this server”。原来是站点2缺少.htaccess
文件。
(1)问题描述
我在AWS EC2同一个实例下挂了2个wordpress,第一个一切正常,第二个除了主页,访问其他页面都提示“The requested URL was not found on this server”。最开始以为是文件权限的原因,还花了不少时间,较为系统了解了下文件的操作权限(详情见《将AWS EC2中网页服务器目录的权限设到最优》),仔细设置好文件(夹)权限后,并且再次检查apache2/sites-available/
下的配置文件,还是不行。
(2)解决方法
最后在StackOverflow提问(问题在这里),今天得到回答,提示我检查.htaccess
文件。一检查,才发现站点2压根就没有.htaccess
文件,于是在站点2目录下创建之,内容如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
现在一切正常了。
(3).htaccess
关于.htaccess
,摘抄维基百科词条.htaccess部分内容如下:
A .htaccess (hypertext access) file is a directory)-level configuration file supported by several web servers, that allows for decentralized management of web server configuration. They are placed inside the web tree, and are able to override a subset of the server's global configuration for the directory that they are in, and all sub-directories.[1]
The original purpose of .htaccess—reflected in its name—was to allow per-directory access control by, for example, requiring a password to access the content. More commonly, however, the .htaccess files override many other configuration settings such as content type,character set, CGI handlers, etc.